<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Request;
use think\Session;

class Base extends Controller
{
    protected $uid;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->setMenu();
        $comment = Db::table('user_comment')
            ->order('created_ts desc')
            ->limit(4)
            ->select();
        $this->assign('comment',$comment);

        $user = Session::get('user_info');
        if($user){
            $this->uid = $user['id'];
        }
        $this->assign('is_login',$user);
    }

    protected function setMenu()
    {
        $action = request()->action();
        $arr = [
            'index'=>1,
            'about'=>2,
            'contact'=>3,
            'user'=>4,
        ];
        if(!empty($arr[$action]) && $arr[$action] > 0){
            $this->assign('active',$arr[$action]);
        }
    }

}
